home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11074 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Coding Standards
  5. Date: Tue, 12 Mar 1996 16:13:58 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4i47qr$q5e@news.halcyon.com>
  8. References: <4hj8ek$elu@sam.inforamp.net> <4hjh5c$elk@flood.weeg.uiowa.edu> <4hv2tm$e93@news.halcyon.com> <4i1ne4$g99@clarknet.clark.net>
  9. NNTP-Posting-Host: blv-pm3-ip12.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. gusty@clark.net (Harlan Messinger) wrote:
  13.  
  14. >Norm Bryar (normanb@halcyon.com) wrote:
  15. >: Except you can't put consts in a header for everyone to use and you
  16. >: can't bitwise-OR enum values.  #defines still have a place.    <===
  17.  
  18. >??? What about a header with the line,
  19.  
  20. >    extern const MyType MYCONST;
  21.  
  22. >and a single module with the global definition
  23.  
  24. >    const MyType MYCONST(/* Initialization parameters here */);
  25.  
  26. This is possible, although different still different than using
  27. #define.   You can't compile 
  28.  
  29.     switch( var )
  30.     {
  31.         case MYCONST:
  32.             ...
  33.  
  34. nor 
  35.  
  36.     #if  MSCVER >= MYCONST
  37.  
  38.  
  39. Probably most damning, however, is you can't easily bring MYCONST
  40. across module boundaries involving DLLs.  With a #define in my header,
  41. both the EXE and the DLL know the value at compile time; with const, I
  42. have to export the data from the DLL (yucky) and tell the EXE to
  43. import the data (yucker!), which restricts me to early-binding to the
  44. DLL, as well as forcing lots of error-prone, hard-to-read overhead.
  45. All this just to avoid #define
  46.  
  47. On the type-safety issue, you can always make your defines more
  48. typesafe
  49.  
  50.     #define A_LONG       (123L)
  51.     #define A_DWORD   ((DWORD) 123u)
  52.  
  53. etc.
  54.  
  55. Trust me, there *is* a place for #define still!
  56.  
  57.                         --Norm 
  58.  
  59.  
  60.